package com.zadtek.shopmall.activities;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.zadtek.shopmall.R;
import com.zadtek.shopmall.base.AbsActivity;
import com.zadtek.shopmall.utils.ToastUtil;

public class NameVerifyActivity extends AbsActivity {
    private EditText etName;
    private EditText etIdcardNumber;
    private EditText etBank;
    private EditText etBankNumber;
    private EditText etPhonenumber;
    private EditText etSmscode;
    private TextView tvSendCode;
    private TextView tvSave;
    private ImageView ivBack;
    private TextView topTitle;

    @Override
    public int setView() {
        return R.layout.activity_name_verify;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
        initView();
        initLogic();
    }

    private void initLogic() {
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tvSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                submitPersonInfo();
            }

        });
        tvSendCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendCode();
            }
        });
    }

    private void sendCode() {
        startCountDown();
        ToastUtil.showToast("发送短信验证码");
    }

    private void submitPersonInfo() {
        String name = etName.getText().toString();
        String idcard = etIdcardNumber.getText().toString();
        String bank = etBank.getText().toString();
        String bankNumber = etBankNumber.getText().toString();
        String phoneNumber = etPhonenumber.getText().toString();
        String smscode = etSmscode.getText().toString();
        if(TextUtils.isEmpty(name)||TextUtils.isEmpty(idcard)||TextUtils.isEmpty(bank)||TextUtils.isEmpty(bankNumber)||TextUtils.isEmpty(phoneNumber)||TextUtils.isEmpty(smscode)){
            ToastUtil.showToast("请完善所有信息后提交！");
            return;
        }
        ToastUtil.showToast("提交信息！");
    }
    private void initView() {
        etName = (EditText)findViewById( R.id.et_name );
        etIdcardNumber = (EditText)findViewById( R.id.et_idcard_number );
        etBank = (EditText)findViewById( R.id.et_bank );
        etBankNumber = (EditText)findViewById( R.id.et_bank_number );
        etPhonenumber = (EditText)findViewById( R.id.et_phonenumber );
        etSmscode = (EditText)findViewById( R.id.et_smscode );
        tvSendCode = (TextView)findViewById( R.id.tv_send_smscode );
        tvSave = (TextView)findViewById( R.id.tv_save );
        ivBack = (ImageView) findViewById(R.id.ic_back);
        ivBack.setVisibility(View.VISIBLE);
        topTitle = (TextView) findViewById(R.id.title);
        topTitle.setText("实名认证");
    }

    private void startCountDown() {
        tvSendCode.setClickable(false);
        CountDownTimer timer = new CountDownTimer(60000,1000) {
            @Override
            public void onTick(long l) {
                tvSendCode.setText(l/1000+"s");
            }
            @Override
            public void onFinish() {
                tvSendCode.setText("发送验证码");
                tvSendCode.setClickable(true);
            }
        };
        timer.start();
    }
}
